﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Coolite.Ext.Web;
using Sagacity.NC.Web.FormForm;
using System.Collections.Generic;

namespace Sagacity.NC.Web.BasicSettings.Student
{
    public partial class StuZaiXiaoList : PageBase
    {
        System.Data.DataTable dtitem = new DataTable();
        /// <summary>
        /// 设置模型参数
        /// </summary>
        private List<Sagacity.Entity.Query.ParameterInfo> modelparams = new List<Sagacity.Entity.Query.ParameterInfo>();
        public List<Sagacity.Entity.Query.ParameterInfo> ModelParams { get { return modelparams; } set { modelparams = value; } }
        /// <summary>
        /// 资源数据过滤条件
        /// </summary>
        private List<Sagacity.Entity.Query.FilterInfo> filters = new List<Sagacity.Entity.Query.FilterInfo>();
        public List<Sagacity.Entity.Query.FilterInfo> Filters { get { return filters; } set { filters = value; } }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                Coolite.Ext.Web.Hidden hidFilters = this.TabFormCommon1.FindControl("hidInterfaceFilters") as Coolite.Ext.Web.Hidden;
                hidFilters.Text = "Student_ID$=$-1";
            }

            this.TabFormCommon1.ResourceId = int.Parse(hidResourceId.Value);
            this.TabFormCommon1.CurrentUser = CurrentUser;
          AddButton();
        }

        /// <summary>
        /// 再次查询当前资源的数据。得到类型
        /// 根据得到的类型判断用户选择的是班级还是学校给出相应参数
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [AjaxMethod]
        public string getSchoolClass(string id, string TableName, string resourceId)
        {
            GetShowDataTable(id,TableName, Convert.ToInt32(resourceId));
            if(dtitem.Rows.Count>0)
            {
               DataRow dtRow= dtitem.Rows[0];
                //如果type=1表示点击的是学校 否则就是班级
               hidtype.Value = dtRow["type"].ToString();
                  string para= "";
                  if (dtRow["type"].ToString() == "1")
                  {
                      para = "School_ID$=$" + Convert.ToInt32(id) / 10000;
                      hidPara.Value = para.Replace("$", "");
                      return para;
                  }
                  else
                  {
                      para = "Class_ID$=$" + id;
                      hidPara.Value = para.Replace("$", "");
                      return para;
                  }
            }
            else
            return"";
        }

        /// <summary>
        /// 获得数据
        /// </summary>
        /// <param name="refresh">是否需要重新刷新</param>
        public void GetShowDataTable(string id,string TableName, int resourceId)
        {
                filters.Add(new Sagacity.Entity.Query.FilterInfo("ID", "=", id));
                dtitem = Sagacity.NC.Business.SysMange.Common.GetRoleRightData(CurrentUser.LoginRole, resourceId, filters, ModelParams);
        }
        public void AddButton()
        {
            //增加按钮
            Coolite.Ext.Web.ToolbarButton btnAdds = new Coolite.Ext.Web.ToolbarButton();
            btnAdds.ID = "btnSign";
            btnAdds.Visible = true;
            btnAdds.Enabled = true;
            btnAdds.Text = "批量签字";
            btnAdds.Icon = Icon.ApplicationEdit;
            btnAdds.Listeners.Click.Handler = "javascript:SignOnClick();";
            this.TabFormCommon1.BtnControls.Add(btnAdds);
        }
        [AjaxMethod]
        public bool btnSignOnClick()
        {
            bool flag = false;
            try
            {
                string query = string.Format(@"update ee_base_StudentInfo set blnIsSign=1
where school_ID in(
 select INTDATAID from RGT_QUERYPROJECTDATA where INTRIGHTPROJECTID=3 and INTROLEID={0})
",CurrentUser.LoginRole.Id);
                 flag = (new Business.SysMange.Common()).ExcuteCommand(query);
           
            }catch(Exception ex)
            {
                flag = false;
            }
            return flag;

        }
        

    }
}
